package com.example.meimessage.group;

import java.util.ArrayList;
import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.example.meimessage.R;

@SuppressLint("UseSparseArrays")
public class GroupAdapter extends BaseAdapter{
	private ArrayList<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();
	private static HashMap<Integer, Boolean> isSelected= new HashMap<Integer, Boolean>();
	private Context context=null;
	
	public GroupAdapter(ArrayList<HashMap<String,Object>> list,Context context){
		this.list=list;
		this.context=context;
		for (int i = 0; i < list.size(); i++) {
			getIsSelected().put(i, false);
		}
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if (convertView == null) {
			holder=new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.group_namelist_mark, null);

			holder.name = (TextView) convertView.findViewById(R.id.group_mark_name);
			holder.checkBox = (CheckBox) convertView.findViewById(R.id.group_checkBox);
			
			convertView.setTag(holder);
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.name.setText(list.get(position).get("group_name").toString());
		holder.checkBox.setChecked(getIsSelected().get(position));
		return convertView;
	}
	public static HashMap<Integer, Boolean> getIsSelected() {
		return isSelected;
	}
	public static class ViewHolder
	{
		private TextView name;
		public CheckBox checkBox;
	}

}
